package cn.echo.consul.manager.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Getter;

import static cn.echo.consul.manager.response.ResultCode.F11400;

/**
 * 异常响应结果类
 * @author lonyee
 */
@Getter
@JsonInclude(Include.NON_NULL)
public class ResultError {

    private Integer code;
	private String msg;

    public ResultError() {
        this(F11400.getMsg());
    }


    public ResultError(String msg) {
        this(F11400.getCode(), msg);
    }

    public ResultError(ResultCode resultCode, String... args) {
        this(resultCode.getCode(), resultCode.getMsg(), args);
    }

    public ResultError(ResultCode resultCode, Throwable ex) {
        this(resultCode.getCode(), resultCode.getMsg(), ex);
    }

    public ResultError(Integer code, String msg, String... args) {
    	this.code = code;
    	this.msg = args.length>0? String.format(msg, args): msg;
    }

    public ResultError(Integer code, String msg, Throwable ex) {
        this(code, ex.getMessage()==null? msg: msg +"，%s", ex.getMessage());
    }
}
